package com.efast.dmom.aps.datahandlers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.cafe.framework.util.SpringWebUtils;
import com.efast.dmom.aps.bean.Station;
import com.efast.dmom.aps.dao.StationDao;
import com.efast.dmom.aps.util.TimeUtil;

@Component
public class StationHandler {
	
	@Autowired
	private StationDao stationDao;
	
	public void save(Station obj) {

		if (obj.getInnerData() != null) {
			obj.getInnerData().setSiteId(DataHandlerUtils.getSiteId());
			obj.getInnerData().setCreationTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setCreationTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setCreator(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
//			obj.getInnerData().setCreationPid(DataHandlerUtils.getDmomPid());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());
			obj.getInnerData().setRowStatus(1);
			obj.getInnerData().setRowTrxId(111);
			stationDao.save(obj.getInnerData());
		}
	}

	public void update(Station obj) {

		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			stationDao.update(obj.getInnerData());
		}
	}

	public void delete(Station obj) {
		if (obj.getInnerData() != null) {

			obj.getInnerData().setLastModifiedTime(TimeUtil.getLocalDateTime());
			obj.getInnerData().setLastModifier(SpringWebUtils.getRequestUser());
			obj.getInnerData().setLastModifiedTimeZone(TimeUtil.getLocalTimeZone());
//			obj.getInnerData().setLastModifiedPid(DataHandlerUtils.getDmomPid());

			stationDao.delete(obj.getInnerData());
		}
	}

	public Station getById(long id) {
		Station station = new Station();
		station.setInnerData(stationDao.getById(id));
		return station;
	}

	public Station getByName(String name) {
		Station station = new Station();
		station.setInnerData(stationDao.getByName(name));
		return station;
	}


	public Station getByCode(String StationCode) {
		Station station = new Station();
		station.setInnerData(stationDao.getByCode(StationCode));
		return station;
	}
	


}
